package com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.util.utils.ToastUtils;
import com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyActivity.BaseActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyActivity.SelectTheAddressActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/30.
 * 呼叫苦力
 */

public class CallCoolieActivity extends BaseActivity implements View.OnClickListener {
    public static final int SELECT_MAP_KEY = 9527;
    public static final String RECIVED_LNG = "recived_lng";
    public static final String RECIVED_LAT = "recived_lat";
    public static final String RECIVED_ADDRESS = "recived_address";
    @Bind(R.id.retur)
    LinearLayout retur;
    @Bind(R.id.addres_layout)
    LinearLayout addres_layout;
    @Bind(R.id.title_center)
    TextView title_center;
    @Bind(R.id.qu_door_number)
    EditText mRecivedAddressEt;
    @Bind(R.id.send_door_number)
    EditText mSendAddressEt;
    @Bind(R.id.recived_person)
    EditText mRecivedPersonEt;
    @Bind(R.id.phone)
    EditText mPhoneEt;
    @Bind(R.id.summary_of_housing_text)
    EditText mBeizhuEt;
    @Bind(R.id.kg)
    EditText mKgEt;
    @Bind(R.id.button)
    Button mCall;
    Context context;
    private String mRecivedLng;
    private String mRecivedLat;
    private String mRecivedAddress;
    private String mDoorNumber;
    private String mSendLng;
    private String mSendLat;
    private String mSendRecivedAddress;
    private String mSendDoorNumber;
    private String mRecivedPreson;
    private String mPhone;
    private String mBeizhu;
    private String mKg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call_coolie);
        ButterKnife.bind(this);
        context = this;
        initView();
    }

    private void initView() {
        retur.setOnClickListener(this);
        addres_layout.setOnClickListener(this);
        mCall.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.retur:
                finish();
                break;
            case R.id.addres_layout:
                Intent intent = new Intent(this, SelectTheAddressActivity.class);
                startActivityForResult(intent, SELECT_MAP_KEY);
                break;
            case R.id.button:
                if (checkData()) {
                    sendPost();
                }
                break;
        }
    }

    private boolean checkData() {
        mDoorNumber = mRecivedAddressEt.getText().toString().trim();
        mSendDoorNumber = mSendAddressEt.getText().toString().trim();
        mRecivedPreson = mRecivedPersonEt.getText().toString().trim();
        mPhone = mPhoneEt.getText().toString().trim();
        mBeizhu = mBeizhuEt.getText().toString().trim();
        mKg = mKgEt.getText().toString().trim();
        if (TextUtils.isEmpty(mRecivedLng) || TextUtils.isEmpty(mRecivedLat) || TextUtils.isEmpty(mRecivedAddress)) {
            ToastUtils.show(this, "请选择取件地址", Toast.LENGTH_SHORT);
            return false;
        }
        if (TextUtils.isEmpty(mDoorNumber)) {
            ToastUtils.show(this, "请输入取件地址门牌号", Toast.LENGTH_SHORT);
            return false;
        }
        if (TextUtils.isEmpty(mSendLat) || TextUtils.isEmpty(mSendLng) || TextUtils.isEmpty(mSendRecivedAddress)) {
            ToastUtils.show(this, "请选择送达的地址", Toast.LENGTH_SHORT);
            return false;
        }
        if (TextUtils.isEmpty(mSendDoorNumber)) {
            ToastUtils.show(this, "请输入送达的门牌号", Toast.LENGTH_SHORT);
            return false;
        }
        if (TextUtils.isEmpty(mRecivedPreson)) {
            ToastUtils.show(this, " 请输入收货人", Toast.LENGTH_SHORT);
            return false;
        }
        if (TextUtils.isEmpty(mPhone)) {
            ToastUtils.show(this, "请输入手机号码", Toast.LENGTH_SHORT);
            return false;
        }
        if (TextUtils.isEmpty(mKg)) {
            ToastUtils.show(this, "请输入大概重量", Toast.LENGTH_SHORT);
            return false;
        }
        return true;
    }

    private void sendPost() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == SELECT_MAP_KEY && resultCode == RESULT_OK) {

        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

